package com.study.webapp.leetcode;

import com.alibaba.fastjson.JSON;
import io.swagger.models.auth.In;

import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;

public class Leet_239 {

    public static void main(String[] args) {

    }







    static class KthLargest {
        final PriorityQueue<Integer> queue;
        final int k;

        public KthLargest (int k, int[] nums) {
            this.k = k;
            queue = new PriorityQueue<>(k);
            for (int a : nums) {
                add(a);
            }
        }

        public int add(int a) {
            if (queue.size() < k) {
                queue.offer(a);
            } else if (queue.peek() < a) {
                queue.poll();
                queue.offer(a);
            }
            return queue.peek();
        }
    }
}
